package tt.dz.egobus.servicemanager.vo;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import tt.dz.egobus.servicemanager.bean.EntityViewVo;
import tt.dz.egobus.servicemanager.entities.BusType;

import javax.validation.constraints.Max;

/**
 * @author Anson
 * @date 17-4-14
 * @name
 * @since 1.0.4
 */
public class BusTypeViewVo implements EntityViewVo<BusType,BusTypeViewVo> {
    private static final long serialVersionUID = 7348291123113278133L;

    private static final Logger LOGGER = LoggerFactory.getLogger(BusTypeViewVo.class);


    @Override
    public BusType convert() {
        BusType pojo = new BusType();
        try {
            BeanUtils.copyProperties(this, pojo);
        } catch (BeansException e) {
            LOGGER.error("BusTypeVo -> BusType bean拷贝异常, viewVo={}", this, e);
        }
        return pojo;
    }

    @Override
    public BusTypeViewVo view(BusType pojo) {
        if (pojo == null) {
            return this;
        }
        try {
            BeanUtils.copyProperties(pojo, this);
        } catch (BeansException e) {
            LOGGER.error("Bus  -> BusViewVo bean拷贝异常, viewVo={}", this, e);
        }
        return this;
    }

    private String id;

    /**
     * 品牌
     */
    @NotBlank(message="车型不能为空")
    @Length(max = 50,message = "车型字符长度不能超过50")
    private String brand;

    /**
     * 型号
     */
    @Length(max = 25,message = "型号字符长度不能超过25")
    private String version;

    /**
     * 车座
     */
    @Max(value=10000,message="座位数不能大于10000")
    private int seatNum;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public int getSeatNum() {
        return seatNum;
    }

    public void setSeatNum(int seatNum) {
        this.seatNum = seatNum;
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) return true;
        if (!(o instanceof BusTypeViewVo)) return false;

        BusTypeViewVo that = (BusTypeViewVo) o;

        if (seatNum != that.seatNum) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (brand != null ? !brand.equals(that.brand) : that.brand != null) return false;
        return version != null ? version.equals(that.version) : that.version == null;

    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (brand != null ? brand.hashCode() : 0);
        result = 31 * result + (version != null ? version.hashCode() : 0);
        result = 31 * result + seatNum;
        return result;
    }

    @Override
    public String toString() {
        return "BusTypeViewVo{" +
                "id='" + id + '\'' +
                ", brand='" + brand + '\'' +
                ", version='" + version + '\'' +
                ", seatNum=" + seatNum +
                '}';
    }
}
